package springboot.mybatis.web;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView;
import springboot.login.WebSecurityConfig;
import springboot.login.domain.User;
import springboot.mybatis.service.impl.TbUserManagementServiceImpl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.xml.transform.Result;
import java.time.chrono.ThaiBuddhistChronology;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author mybatis_plus
 * @since 2017-12-04
 */
@Controller
public class TbUserManagementController {

    @Autowired
    TbUserManagementServiceImpl tbUserManagementService;

//    @RequestMapping("/login")
//    public String toTestUrl(){
//
//        System.out.println("login: 跳转");
//        return "resources/templates/login.html";
//    }
//
//    @RequestMapping("/index")
//    public ModelAndView testUrl(String username){
//
//        String message = tbUserManagementService.test(username);
//
//
//        return new ModelAndView("index","message",message);
//    }
//    @GetMapping("/")
//    public String index(@SessionAttribute(WebSecurityConfig.SESSION_KEY)String account, Model model){
//
//        return "index";
//    }

    @GetMapping("/login")
    public String login(){
        return "login";
    }

    @PostMapping("/loginVerify")
    public String loginVerify(String username, HttpServletRequest request){
        String message = tbUserManagementService.test(username);
            request.setAttribute("message", message);
            return "login";

    }

    @GetMapping("/logout")
    public String logout(HttpSession session){
        session.removeAttribute("message");
        return "redirect:/login";
    }
}

